/* rcsqprt.p    -  PRINTING SEQUENCE RANGE FOR SHIPPERS AND INVOICES        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/*V8:ConvertMode=NoConvert                                                  */
/*V8:RunMode=Character,Windows                                              */
/* REVISION: 9.1            CREATED: 06/18/99       BY: *N003* Patrick Rowan*/
/* REVISION: 9.1      LAST MODIFIED: 08/12/00       BY: *N0KP* myb          */
/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: This program reads through the abss_det table to find records
              for a shipper (parm #1) or and invoice (part #2).  A table is
              created that contains the from-and-to ranges for the sequences.

 ============================================================================
 !*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */


         {mfdeclre.i}


         /* INPUT VARIABLES */
         define input parameter abs_recid as recid no-undo.
         define input parameter inv_nbr like so_inv_nbr no-undo.


         /* LOCAL VARIABLES */
         define variable t_abss_det_recid as recid no-undo.
         define variable t_print_shipper as logical initial no no-undo.
         define variable t_print_invoice as logical initial no no-undo.


         /* SHARED VARIABLES */
         define     shared temp-table t_abss_det no-undo
            field t_abss_ship_id        like abss_ship_id
            field t_abss_from_cust_job  like abss_cust_job
            field t_abss_from_cust_seq  like abss_cust_seq
            field t_abss_to_cust_job    like abss_cust_job
            field t_abss_to_cust_seq    like abss_cust_seq.


         /* INITIALIZATION */
          for first rcf_ctrl no-lock: end.



          /* CHECK TO SEE IF SEQUENCE SHOULD PRINT ON SHIPPER */

         for first abs_mstr where
            recid(abs_mstr) = abs_recid
            no-lock: end.
          if available (abs_mstr) then do:
              for first rcc_mstr where
                rcc_addr = abs_shipto no-lock: end.

              if available rcc_mstr and rcc_shipper_print
                        or
                (not available rcc_mstr and
                     available rcf_ctrl and
                     rcf_shipper_print) then
                        t_print_shipper = yes.
          end.  /* if available (abs_mstr) */



          /* CHECK TO SEE IF SEQUENCE SHOULD PRINT ON INVOICE */

         for first abss_det where
            abss_invoice = inv_nbr
            no-lock: end.

          if available (abss_det) then do:
              for first rcc_mstr where
                rcc_addr = abss_shipto no-lock: end.

              if available rcc_mstr and rcc_invoice_print
                        or
                (not available rcc_mstr and
                     available rcf_ctrl and
                     rcf_invoice_print) then
                        t_print_invoice = yes.
          end.  /* if available (abss_det) */




         /* FIND THE SEQUENCES FOR THE SHIPPER LINE */
         if available (abs_mstr) and t_print_shipper then do:
            for each abss_det where
                abss_ship_id   = abs_id and
                abss_shipfrom  = abs_shipfrom
                use-index abss_index4
                no-lock
                break by abss_cust_job
                      by abss_cust_seq:


                /* SAVE BEGINNING RANGE */
                if first-of(abss_cust_job) then do:
                    create t_abss_det.
                    assign
                        t_abss_ship_id  = abss_ship_id
                        t_abss_from_cust_job
                                        = abss_cust_job
                        t_abss_from_cust_seq
                                        = abss_cust_seq
                        t_abss_to_cust_job
                                        = abss_cust_job
                        t_abss_to_cust_seq
                                        = abss_cust_seq
                        t_abss_det_recid = recid(t_abss_det).
                    next.
                end.  /* if first(abss_cust_job) */


                /* DETERMINE IF WITHIN RANGE */
                if can-find(first rcsd_det where
                                rcsd_shipfrom   = abss_shipfrom and
                                rcsd_shipto     = abss_shipto   and
                                rcsd_rlse_id    = abss_rlse_id  and

                               (rcsd_cust_job   > t_abss_to_cust_job or
                               (rcsd_cust_job   = t_abss_to_cust_job and
                                rcsd_cust_seq   > t_abss_to_cust_seq))
                                              and
                               (rcsd_cust_job   < abss_cust_job or
                               (rcsd_cust_job   = abss_cust_job and
                                rcsd_cust_seq   < abss_cust_seq)))
                    then do:
                        create t_abss_det.
                        assign
                            t_abss_ship_id  = abss_ship_id
                            t_abss_from_cust_job
                                            = abss_cust_job
                            t_abss_from_cust_seq
                                            = abss_cust_seq
                            t_abss_to_cust_job
                                            = abss_cust_job
                            t_abss_to_cust_seq
                                            = abss_cust_seq
                            t_abss_det_recid = recid(t_abss_det).
                end.  /* if can-find(first rcsd_det) */
                else
                    assign
                        t_abss_to_cust_job
                                    = abss_cust_job
                        t_abss_to_cust_seq
                                    = abss_cust_seq.


            end.  /* for each abss_det */


         end.  /* if available (abs_mstr) */
         else do:
             if available (abss_det) and t_print_invoice then do:

                /* FIND THE SEQUENCES FOR THE INVOICE */
                for each abss_det where
                    abss_invoice    = inv_nbr
                    use-index abss_index7
                    no-lock
                    break by abss_cust_job
                          by abss_cust_seq:


                    /* SAVE BEGINNING RANGE */
                    if first-of(abss_cust_job) then do:
                        create t_abss_det.
                        assign
                            t_abss_ship_id  = abss_ship_id
                            t_abss_from_cust_job
                                            = abss_cust_job
                            t_abss_from_cust_seq
                                            = abss_cust_seq
                            t_abss_to_cust_job
                                            = abss_cust_job
                            t_abss_to_cust_seq
                                            = abss_cust_seq
                            t_abss_det_recid = recid(t_abss_det).
                        next.
                    end.  /* if first(abss_cust_job) */

                    /* DETERMINE IF WITHIN RANGE */
                    if can-find(first rcsd_det where
                                    rcsd_shipfrom   = abss_shipfrom and
                                    rcsd_shipto     = abss_shipto   and
                                    rcsd_rlse_id    = abss_rlse_id  and

                                   (rcsd_cust_job   > t_abss_to_cust_job or
                                   (rcsd_cust_job   = t_abss_to_cust_job and
                                    rcsd_cust_seq   > t_abss_to_cust_seq))
                                                   and
                                   (rcsd_cust_job   < abss_cust_job or
                                   (rcsd_cust_job   = abss_cust_job and
                                    rcsd_cust_seq   < abss_cust_seq)))
                      then do:
                            create t_abss_det.
                            assign
                                t_abss_ship_id  = abss_ship_id
                                t_abss_from_cust_job
                                                = abss_cust_job
                                t_abss_from_cust_seq
                                                = abss_cust_seq
                                t_abss_to_cust_job
                                                = abss_cust_job
                                t_abss_to_cust_seq
                                                = abss_cust_seq
                                t_abss_det_recid = recid(t_abss_det).
                    end.  /* if can-find(first rcsd_det) */
                    else do:
                        assign
                            t_abss_to_cust_job
                                        = abss_cust_job
                            t_abss_to_cust_seq
                                        = abss_cust_seq.

                    end.
                end.  /* for each abss_det */

             end.  /* if available (abss_det) and t_print_invoice */
         end.  /* else do */
